package com.sywb.chuangyebao.contract;

import android.app.Activity;
import android.media.MediaPlayer;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.alibaba.fastjson.JSON;
import com.czt.mp3recorder.MP3Player;
import com.sywb.chuangyebao.Constants;
import com.sywb.chuangyebao.R;
import com.sywb.chuangyebao.bean.HistoryInfo;
import com.sywb.chuangyebao.bean.NewsInfo;
import com.sywb.chuangyebao.bean.QuestionInfo;
import com.sywb.chuangyebao.bean.SuperInfo;
import com.sywb.chuangyebao.bean.VideoData;
import com.sywb.chuangyebao.library.view.RatioImageView;
import com.sywb.chuangyebao.utils.DateTimeUtils;
import com.sywb.chuangyebao.utils.GlideUtils;
import com.sywb.chuangyebao.utils.HttpCallback;
import com.sywb.chuangyebao.utils.HttpUtils;
import com.sywb.chuangyebao.utils.Utils;
import com.sywb.chuangyebao.view.NewsDetailActivity;
import com.sywb.chuangyebao.view.QAndADetailActivity;
import com.sywb.chuangyebao.view.TopicActivity;
import com.sywb.chuangyebao.view.VideoDetailActivity;
import com.sywb.chuangyebao.view.WebActivity;
import com.sywb.chuangyebao.widget.RichTextView;

import org.bining.footstone.adapter.BaseRecyclerMultiItemAdapter;
import org.bining.footstone.adapter.ViewHolderHelper;
import org.bining.footstone.log.Logger;
import org.bining.footstone.rxjava.rxbus.RxBus;
import org.bining.footstone.utils.TimeUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

public interface UserHistoryContract {

    interface View extends BasePlayerContract.View {
        /**
         * 隐藏右上角的清空菜单
         *
         * @param visible 是否隐藏
         */
        void hideMenu(boolean visible);
    }

    class Presenter extends BasePlayerContract.Presenter<View> {

        protected HistoryAdapter recyclerAdapter;
        int pageNumber = 1;

        private int currentAudioPosition;
        private QuestionInfo currentAudioQuestion;

        private SuperInfo lastTime;

        @Override
        public void onStart() {
            super.onStart();
            recyclerAdapter = new HistoryAdapter(mActivity, mView);
            setRecyclerAdapter(recyclerAdapter);
            recyclerAdapter.setPageSize(1);

            initData();
        }

        @Override
        public void initData() {
            Logger.e("UserHistoryContract initData");
            onStartAsync();
            getHistoryData();
        }

        @Override
        public void onStartRefresh() {
            super.onStartRefresh();
            Logger.e("UserHistoryContract onStartRefresh");
            pageNumber = 1;
            getHistoryData();
        }

        @Override
        public void onStartLoadMore() {
            Logger.e("UserHistoryContract onStartLoadMore");
            pageNumber++;
            getHistoryData();
        }

        @Override
        public void isNoData() {
            super.isNoData();
            if (recyclerAdapter != null && mView != null) {
                mView.hideMenu(recyclerAdapter.getDatas() != null && !recyclerAdapter.getDatas().isEmpty());
            }
        }

        public void clearHistory() {
            HttpUtils.clearHistory(new HttpCallback<String>() {

                @Override
                public void onStart() {
                    super.onStart();
                    onStartAsync();
                }

                @Override
                public void onSuccess(String result) {
                    recyclerAdapter.clearDatas();
                    recyclerAdapter.notifyDataSetChanged();
                    isNoData();
                    showMessage(R.string.clear_history_success);
                }

                @Override
                public void onError(String strMsg) {
                    super.onError(strMsg);
                    showMessage(strMsg);
                }

                @Override
                public void onFinish() {
                    super.onFinish();
                    onFinishAsync();
                }
            });
        }

        public void getHistoryData() {
            HttpUtils.getHistory(pageNumber, new HttpCallback<List<HistoryInfo>>() {
                @Override
                public void onSuccess(List<HistoryInfo> historyInfos) {
                    List<SuperInfo> superInfoList = new ArrayList<>();
                    if (historyInfos != null && historyInfos.size() > 0) {
                        for (HistoryInfo historyInfo : historyInfos) {
                            SuperInfo titleSuperInfo = new SuperInfo();
                            titleSuperInfo.setItemType(Constants.USER_LIST);
                            titleSuperInfo.item_style = Constants.USER_LIST;
                            titleSuperInfo.content = historyInfo.time + "阅读了" + historyInfo.num + "篇";
                            titleSuperInfo.keyword = historyInfo.time;

                            if (pageNumber == 1 || lastTime == null || !lastTime.keyword.equals(historyInfo.time)) {
                                lastTime = titleSuperInfo;
                                superInfoList.add(lastTime);
                            }

                            for (SuperInfo superInfo : historyInfo.info) {
                                superInfo.setItemType(superInfo.item_style);
                            }

                            superInfoList.addAll(historyInfo.info);
                        }
                    }
                    if (pageNumber == 1) {
                        onEndRefresh();
//                        if (superInfoList.size() > 0) {
//                            recyclerAdapter.setFooterView(R.layout.layout_footer);
//                        } else {
//                            recyclerAdapter.setFooterView(null);
//                        }
                        recyclerAdapter.setFooterView(null);
                        recyclerAdapter.clearDatas();
                    } else {
                        if (superInfoList.size() > 0) {
                            recyclerAdapter.setFooterView(R.layout.layout_footer);
                        } else {
                            recyclerAdapter.setFooterView(null);
                        }
                    }
                    recyclerAdapter.notifyDataChangedAfterLoadMore(superInfoList);
                }

                @Override
                public void onError(String strMsg) {
                    super.onError(strMsg);
                    if (pageNumber == 1) {
                        onEndRefresh();
                    } else {
                        onEndLoadMore();
                    }
                    showMessage(strMsg);
                }

                @Override
                public void onFinish() {
                    super.onFinish();
                    onFinishAsync();
                    isNoData();
                }
            });

        }

        @Override
        public void onRecyclerItemClick(int i) {
            SuperInfo superInfo = recyclerAdapter.getItem(i);
            switch (superInfo.item_style) {
                case 100:
                case 101:
                case 102:
                case 103:
                    NewsInfo newsInfo = JSON.parseObject(superInfo.content, NewsInfo.class);
                    if (newsInfo.item_id == 0) {
                        return;
                    }
                    if (!newsInfo.is_ad) {
                        newsInfo.hits += 1;
                        newsInfo.count.hits += 1;
                        superInfo.content = JSON.toJSONString(newsInfo);
                        recyclerAdapter.notifyDataSetChanged();
                        mView.advance(NewsDetailActivity.class, newsInfo.item_id);
                    } else {
                        mView.advance(WebActivity.class, "", newsInfo.url);
                    }
                    break;
                case 200:
                case 201:
                case 202:
                case 203:
                    QuestionInfo question = JSON.parseObject(superInfo.content, QuestionInfo.class);
                    if (question.item_id == 0) {
                        return;
                    }
                    mView.advance(QAndADetailActivity.class, question.item_id);
                    break;
                case 300:
                    VideoData videoInfo = JSON.parseObject(superInfo.content, VideoData.class);
                    if (videoInfo.item_id == 0) {
                        return;
                    }
                    mView.advance(VideoDetailActivity.class, videoInfo.item_id);
                    break;
            }
        }

        @Override
        public void onRecyclerItemChildClick(android.view.View view, int i) {
            if (view.getId() == R.id.tv_more) {
                RxBus.get().post(Constants.TOPIC_TYPE_USER, Constants.TOPIC_TYPE_USER);
            } else if (view.getId() == R.id.iv_player) {
                VideoData videoInfo = JSON.parseObject(recyclerAdapter.getItem(i).content, VideoData.class);
                startPlayer(i, videoInfo.url, videoInfo.logo, videoInfo.currentPosition);
            } else {
                QuestionInfo question = JSON.parseObject(recyclerAdapter.getItem(i).content, QuestionInfo.class);
                switch (view.getId()) {
                    case R.id.iv_face:
                    case R.id.iv_user_type:
                    case R.id.tv_collection_name:
                    case R.id.tv_collection_time:
                        Utils.goUserIndex(mView, question.owner.uid);
//                        mView.advance(UserIndexActivity.class, question.owner.uid);
                        break;
                    case R.id.richTextView:
                        onRecyclerItemClick(i);
                        break;
                    case R.id.iv_img0:
                        Utils.goBigPic(mActivity, 0, question.pic);
                        break;
                    case R.id.iv_img1:
                        Utils.goBigPic(mActivity, 1, question.pic);
                        break;
                    case R.id.iv_img2:
                        Utils.goBigPic(mActivity, 2, question.pic);
                        break;
                    case R.id.iv_media_type:
                        //播放语音
                        if (currentAudioQuestion == null || currentAudioPosition != i) {
                            currentAudioPosition = i;
                            currentAudioQuestion = question;
                        }
                        playAudio(question.audio);
                        recyclerAdapter.notifyDataSetChanged();
                        break;
                }
            }
        }

        @Override
        public void saveItemPlayerCurrentPosition(int postion, long currentPosition) {
            SuperInfo superInfo = recyclerAdapter.getItem(postion);
            if (superInfo.item_style == Constants.VIDEO_LIST) {
                VideoData videoInfo = JSON.parseObject(superInfo.content, VideoData.class);
                videoInfo.currentPosition = currentPosition;
                superInfo.content = JSON.toJSONString(videoInfo);
            }
        }

        @Override
        public void onDestroy() {
            super.onDestroy();
            if (mp3Player != null) {
                mp3Player.stopPlay();
                mp3Player = null;
            }
        }

        private MP3Player mp3Player;
        private boolean isPlaying;
        private String playingAudioUrl;

        private void playAudio(String currentAudioUrl) {
            //播放语音
            if (mp3Player == null) {
                mp3Player = MP3Player.getInstance();
                mp3Player.setOnMP3PlayerListener(new MP3Player.OnMP3PlayerListener() {
                    @Override
                    public void onCompletion(MediaPlayer mediaPlayer) {
                        Logger.e("MediaPlayer onCompletion:");
                        currentAudioQuestion.progress = 0;
                        playStop();
                    }

                    @Override
                    public void onSeekComplete(MediaPlayer mediaPlayer) {
                        Logger.e("MediaPlayer onSeekComplete:");
                    }

                    @Override
                    public void onError(MediaPlayer mediaPlayer) {
                        onCompletion(mediaPlayer);
                        showMessage("播放错误,请稍候再试");
                    }
                });

                mp3Player.setOnMP3PlayerStartListener(new MP3Player.onMP3PlayerStartListener() {
                    @Override
                    public void onStart(MediaPlayer mediaPlayer) {
                        Logger.e("duration:" + mp3Player.getMediaPlayer().getDuration());
//                        seekbar.setMax(mp3Player.getMediaPlayer().getDuration());
//                        tvAudioTime.setText(DateTimeUtils.getMediaTimeNumber(seekbar.getMax() / 1000));
                        currentAudioQuestion.max = mp3Player.getMediaPlayer().getDuration();
                        recyclerAdapter.notifyDataSetChanged();
                        startTimer();
                    }
                });

                mp3Player.startPlay(currentAudioUrl, null);
                isPlaying = true;
                playingAudioUrl = currentAudioUrl;
                return;
            }
            Logger.e("是否点击同一个：" + currentAudioUrl.equals(playingAudioUrl) + "是否在播：" + isPlaying);

            if (currentAudioUrl.equals(playingAudioUrl)) {
                if (isPlaying) {
                    playStop();
                } else {
                    mp3Player.restart();
                    isPlaying = true;
                    startTimer();
                }
            } else {
                if (isPlaying) {
                    mp3Player.stopPlay();
                }
                currentAudioQuestion.progress = 0;
                playStop();
                mp3Player.startPlay(currentAudioUrl, null);
                isPlaying = true;
                startTimer();
            }
            playingAudioUrl = currentAudioUrl;
        }

        public void playStop() {
            isPlaying = false;
            if (recyclerAdapter != null) {
                recyclerAdapter.notifyDataSetChanged();
            }
            stopTimer();
        }

        private Timer mTimer;
        private boolean isChanging = false;//互斥变量，防止定时器与SeekBar拖动时进度冲突


        private void startTimer() {
            if (currentAudioQuestion.progress > 0) {
                mp3Player.getMediaPlayer().seekTo(currentAudioQuestion.progress);
            }

            //----------定时器记录播放进度---------//
            isChanging = false;
            mTimer = new Timer();
            TimerTask mTimerTask = new TimerTask() {
                @Override
                public void run() {
                    if (isChanging) {
                        return;
                    }

                    try {
                        if (mp3Player.getMediaPlayer() == null) {
                            return;
                        }

//                        seekbar.setProgress(mp3Player.getMediaPlayer().getCurrentPosition());
                        currentAudioQuestion.progress = mp3Player.getMediaPlayer().getCurrentPosition();

//                        tvCurrentTime.setText(DateTimeUtils.getMediaTimeNumber(seekBar.getProgress() / 1000));
                        mActivity.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                recyclerAdapter.notifyDataSetChanged();
                            }
                        });
                        Logger.e("currentPosition:" + mp3Player.getMediaPlayer().getCurrentPosition());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            };
            mTimer.schedule(mTimerTask, 0, 500);
        }


        private void stopTimer() {
            if (mp3Player != null) {
                mp3Player.pause();
            }

            if (mTimer != null) {
                isChanging = true;
                mTimer.cancel();
                Logger.e("stopTimer");
            }
        }

        class HistoryAdapter extends BaseRecyclerMultiItemAdapter<SuperInfo> {

            private Activity mActivity;
            private UserHistoryContract.View mView;

            public HistoryAdapter(Activity activity, UserHistoryContract.View view) {
                super(activity, null);
                this.mActivity = activity;
                this.mView = view;
                addItemType(Constants.USER_LIST, R.layout.item_user_history);
                addItemType(Constants.NEWS_TEXT, R.layout.item_news_text);//文章纯文字布局
                addItemType(Constants.NEWS_RIGHT_PIC_VIDEO, R.layout.item_news_right_pic);//文章右侧小图布局
                addItemType(Constants.NEWS_CENTER_SINGLE_PIC, R.layout.item_news_center_pic);//文章居中大图布局
                addItemType(Constants.NEWS_THREE_PICS, R.layout.item_news_three_pics);//文章三张图片布局
                addItemType(Constants.QANDA_TEXT, R.layout.item_user_dynamic_text);//问答纯文字布局
                addItemType(Constants.QANDA_PIC_ONE, R.layout.item_user_dynamic_pic_one);//问答右侧小图布局
                addItemType(Constants.QANDA_PIC_THREE, R.layout.item_user_dynamic_pic_three);//问答多图布局
                addItemType(Constants.QANDA_MEDIA, R.layout.item_user_dynamic_media);//问答多媒体布局
                addItemType(Constants.VIDEO_LIST, R.layout.item_video_center_pic);//视频布局
            }

            @Override
            protected int getDefItemViewType(int position) {
                if (position >= getDataCount()) {
                    return 0x00000333;
                }
                return super.getDefItemViewType(position);
            }

            @Override
            protected void setMultiData(ViewHolderHelper viewHolderHelper, int i, SuperInfo superInfo) {
                if (superInfo.item_style == Constants.USER_LIST) {
                    viewHolderHelper.setText(R.id.tv_user_history, superInfo.content);
                } else if (superInfo.item_style >= Constants.NEWS_TEXT && superInfo.item_style <= Constants.NEWS_THREE_PICS) {
                    NewsInfo newsInfo = JSON.parseObject(superInfo.content, NewsInfo.class);

                    if (TextUtils.isEmpty(newsInfo.title)) {
                        return;
                    }

                    viewHolderHelper.setVisibility(R.id.tv_author, true);

                    if (newsInfo.owner != null) {
                        viewHolderHelper.setText(R.id.tv_author, newsInfo.owner.getShowName());
                    } else {
                        viewHolderHelper.setText(R.id.tv_author, newsInfo.writer);
                    }

                    viewHolderHelper.setText(R.id.tv_title, newsInfo.title)
                            .setText(R.id.tv_time, TimeUtils.transformDate10(newsInfo.publish_time));

                    viewHolderHelper.setVisibility(R.id.tv_tag, android.view.View.GONE);

                    if (newsInfo.is_ad) {
                        viewHolderHelper.setVisibility(R.id.tv_comment_num, android.view.View.GONE);
                        viewHolderHelper.setVisibility(R.id.tv_tag, android.view.View.VISIBLE).setText(R.id.tv_tag, "广告");
                    } else {
                        viewHolderHelper.setVisibility(R.id.tv_tag, android.view.View.GONE);
                        viewHolderHelper.setVisibility(R.id.tv_comment_num, android.view.View.VISIBLE);
                        viewHolderHelper.setText(R.id.tv_comment_num, newsInfo.count != null ? newsInfo.count.getHitsString() : "0阅读");
                    }

                    switch (superInfo.getItemType()) {
                        case Constants.NEWS_THREE_PICS:
                            RatioImageView iv_img1 = viewHolderHelper.getView(R.id.iv_img1);
                            RatioImageView iv_img2 = viewHolderHelper.getView(R.id.iv_img2);
                            RatioImageView iv_img3 = viewHolderHelper.getView(R.id.iv_img3);

                            iv_img1.setVisibility(android.view.View.INVISIBLE);
                            iv_img2.setVisibility(android.view.View.INVISIBLE);
                            iv_img3.setVisibility(android.view.View.INVISIBLE);

                            if (newsInfo.thumbnails != null && newsInfo.thumbnails.size() > 0) {
                                for (int j = 0; j < newsInfo.thumbnails.size(); j++) {
                                    String thumbnail = newsInfo.thumbnails.get(j).trim();
                                    if (!TextUtils.isEmpty(thumbnail)) {
                                        switch (j) {
                                            case 0:
                                                iv_img1.setVisibility(android.view.View.VISIBLE);
                                                GlideUtils.getNormalIamgeToUrl(mActivity, thumbnail, iv_img1, R.drawable.news_pic_default);
                                                break;
                                            case 1:
                                                iv_img2.setVisibility(android.view.View.VISIBLE);
                                                GlideUtils.getNormalIamgeToUrl(mActivity, thumbnail, iv_img2, R.drawable.news_pic_default);
                                                break;
                                            case 2:
                                                iv_img3.setVisibility(android.view.View.VISIBLE);
                                                GlideUtils.getNormalIamgeToUrl(mActivity, thumbnail, iv_img3, R.drawable.news_pic_default);
                                                break;
                                        }
                                    }
                                }
                            }
                            break;
                        case Constants.NEWS_RIGHT_PIC_VIDEO:
                            RatioImageView iv_img_right = viewHolderHelper.getView(R.id.iv_img);
                            iv_img_right.setImageResource(R.drawable.news_pic_default);
                            if (newsInfo.thumbnails != null && newsInfo.thumbnails.size() > 0 && !TextUtils.isEmpty(newsInfo.thumbnails.get(0).trim())) {
                                GlideUtils.getNormalIamgeToUrl(mActivity, newsInfo.thumbnails.get(0), iv_img_right, R.drawable.news_pic_default);
                            }
                            viewHolderHelper.setVisibility(R.id.tv_duration, android.view.View.GONE);
                            break;
                        case Constants.NEWS_CENTER_SINGLE_PIC:
                            RatioImageView iv_img_center = viewHolderHelper.getView(R.id.iv_img);
                            iv_img_center.setImageResource(R.drawable.news_pic_default);
                            if (newsInfo.thumbnails != null && newsInfo.thumbnails.size() > 0 && !TextUtils.isEmpty(newsInfo.thumbnails.get(0).trim())) {
                                GlideUtils.getNormalIamgeToUrl(mActivity, newsInfo.thumbnails.get(0), iv_img_center, R.drawable.news_pic_default);
                            }
                            viewHolderHelper.setVisibility(R.id.tv_duration, android.view.View.GONE);
                            break;
                    }
                } else if (superInfo.item_style >= Constants.QANDA_TEXT && superInfo.item_style <= Constants.QANDA_MEDIA) {
                    QuestionInfo model = JSON.parseObject(superInfo.content, QuestionInfo.class);
                    model.setTopic();

                    //设置提问人头像
                    ImageView imageFace = viewHolderHelper.getView(R.id.iv_face);
                    GlideUtils.getCircleImageToUrl(mActivity, model.owner.getShowAvatar(), imageFace, R.drawable.head_image);

                    //设置提问人角色类型
                    Utils.setUserRoleIcon((ImageView) viewHolderHelper.getView(R.id.iv_user_type), model.owner.user_role);

                    //设置提问人名称
                    viewHolderHelper.setText(R.id.tv_collection_name, model.owner.getShowName());

                    //设置提问时间
                    viewHolderHelper.setText(R.id.tv_collection_time, DateTimeUtils.getFormatForMinusMonthDayMinutesSecond(model.create_time));

                    // 隐藏头部右边 的 推荐 按钮
                    viewHolderHelper.setVisibility(R.id.tv_recommend, false);

                    viewHolderHelper.setVisibility(R.id.tv_recommend_red, false);
                    viewHolderHelper.setText(R.id.tv_bottom_left, model.count.getAnswer());

                    //设置分类
                    // viewHolderHelper.setText(R.id.tv_bottom_right, model.categoryName);
                    viewHolderHelper.setVisibility(R.id.tv_bottom_right, false);

                    viewHolderHelper.setItemChildClickListener(R.id.iv_face);
                    viewHolderHelper.setItemChildClickListener(R.id.iv_user_type);
                    viewHolderHelper.setItemChildClickListener(R.id.tv_collection_name);
                    viewHolderHelper.setItemChildClickListener(R.id.tv_collection_time);
                    viewHolderHelper.setItemChildClickListener(R.id.richTextView);

                    //设置富文本
                    RichTextView richTextView = viewHolderHelper.getView(R.id.richTextView);
                    richTextView.setDeviationDP(R.dimen.dp_32);

                    switch (superInfo.getItemType()) {
                        case Constants.QANDA_TEXT:
                            break;
                        case Constants.QANDA_PIC_ONE:
                            //设置图片（一张）
                            ImageView imageView = viewHolderHelper.getView(R.id.iv_img);
                            GlideUtils.getNormalIamgeToUrl(mActivity, model.pic.get(0), imageView);
                            richTextView.setDeviationDP(R.dimen.dp_172);
                            break;
                        case Constants.QANDA_PIC_THREE:
                            if (model.pic != null) {
                                if (model.pic.size() > 0) {
                                    viewHolderHelper.setVisibility(R.id.iv_img0, true);
                                    viewHolderHelper.setItemChildClickListener(R.id.iv_img0);
                                    ImageView imageView0 = viewHolderHelper.getView(R.id.iv_img0);
                                    GlideUtils.getNormalIamgeToUrl(mActivity, model.pic.get(0), imageView0);
                                } else {
                                    viewHolderHelper.setVisibility(R.id.iv_img0, false);
                                    viewHolderHelper.setVisibility(R.id.iv_img1, false);
                                    viewHolderHelper.setVisibility(R.id.iv_img2, false);
                                    break;
                                }
                                if (model.pic.size() > 1) {
                                    viewHolderHelper.setVisibility(R.id.iv_img1, true);
                                    viewHolderHelper.setItemChildClickListener(R.id.iv_img1);
                                    ImageView imageView1 = viewHolderHelper.getView(R.id.iv_img1);
                                    GlideUtils.getNormalIamgeToUrl(mActivity, model.pic.get(1), imageView1);
                                } else {
                                    viewHolderHelper.setVisibility(R.id.iv_img1, false);
                                    viewHolderHelper.setVisibility(R.id.iv_img2, false);
                                    break;
                                }
                                if (model.pic.size() > 2) {
                                    viewHolderHelper.setVisibility(R.id.iv_img2, true);
                                    viewHolderHelper.setItemChildClickListener(R.id.iv_img2);
                                    ImageView imageView2 = viewHolderHelper.getView(R.id.iv_img2);
                                    GlideUtils.getNormalIamgeToUrl(mActivity, model.pic.get(2), imageView2);
                                } else {
                                    viewHolderHelper.setVisibility(R.id.iv_img2, false);
                                }
                            }
                            break;
                        case Constants.QANDA_MEDIA:
//                        //设置语音背景图片(用户头像)
//                        ImageView mediaImage = viewHolderHelper.getView(R.id.iv_media);
//                        GlideUtils.getNormalIamgeToUrl(mActivity, model.owner.getShowAvatar(), mediaImage);
//                        //设置语音时长
//                        viewHolderHelper.setText(R.id.tv_audio_time, model.audioLength);
                            if (currentAudioQuestion != null && currentAudioQuestion.item_id == model.item_id && currentAudioPosition == i) {
                                Utils.setQuestionAudioItemView(viewHolderHelper, mActivity, currentAudioQuestion, playingAudioUrl, mp3Player, isPlaying);
                            } else {
                                Utils.setQuestionAudioItemView(viewHolderHelper, mActivity, model, playingAudioUrl, mp3Player, isPlaying);
                            }
                            break;
                    }

                    richTextView.setDataPostion(i);
                    richTextView.setExpandView(true);
                    richTextView.setExpandedOpen(false);
                    richTextView.setRichText(model.title, model.richInfoList);
                    richTextView.setOnLinkClickListener(new RichTextView.OnLinkClickListener() {
                        @Override
                        public void onAtClick(RichTextView richTextView, Object userId) {
//                            mView.advance(UserIndexActivity.class, userId);
                            Utils.goUserIndex(mView, (Integer) userId);
                        }

                        @Override
                        public void onTopicClick(RichTextView richTextView, Object topicId) {
                            mView.advance(TopicActivity.class, topicId);
                        }

                        @Override
                        public void onEmojiClick(RichTextView richTextView, Object emoji) {

                        }

                        @Override
                        public void onUrlClick(RichTextView richTextView, Object url) {

                        }

                        @Override
                        public void onAllClick(RichTextView richTextView) {
                            SuperInfo superInfo = getItem(richTextView.getDataPostion());
                            QuestionInfo model = JSON.parseObject(superInfo.content, QuestionInfo.class);
                            mView.advance(QAndADetailActivity.class, model.item_id);
                        }
                    });

                } else if (superInfo.item_style == Constants.VIDEO_LIST) {
                    VideoData videoInfo = JSON.parseObject(superInfo.content, VideoData.class);

                    ImageView ivImg = viewHolderHelper.getView(R.id.iv_img);
                    GlideUtils.getNormalIamgeToUrl(mActivity, videoInfo.logo, ivImg);

                    viewHolderHelper.setText(R.id.tv_title, videoInfo.title);
                    viewHolderHelper.setText(R.id.tv_duration, DateTimeUtils.secToTime(videoInfo.length));
                    viewHolderHelper.setVisibility(R.id.tv_tag, false);

                    viewHolderHelper.setVisibility(R.id.tv_author, true);

                    viewHolderHelper.setText(R.id.tv_author, videoInfo.owner.getShowName());
                    viewHolderHelper.setText(R.id.tv_comment_num, videoInfo.count.getPlayTimesTotal());
                    viewHolderHelper.setText(R.id.tv_time, TimeUtils.transformDate10(videoInfo.publish_time));

                    FrameLayout llContainer = viewHolderHelper.getView(R.id.ll_container);
                    ViewGroup.LayoutParams layoutParams = llContainer.getLayoutParams();
                    layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
                    layoutParams.height = (int) (org.bining.footstone.utils.ScreenUtils.getScreenWidth() * 0.56F);
                    llContainer.setLayoutParams(layoutParams);

                    viewHolderHelper.setItemChildClickListener(R.id.iv_player);
                }
            }
        }
    }

}
